package com.denlaku.longan.repository;

import com.denlaku.longan.dao.ConditionDao;
import com.denlaku.longan.vo.Condition;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author tianx
 */
@Repository
public class ConditionRepository {
    @Autowired
    private ConditionDao conditionDao;

    /**
     * 批量保存过滤器
     *
     * @param conditionList 组件过滤器列表
     */
    public void batchAdd(List<Condition> conditionList) {
        List<List<Condition>> partitions = ListUtils.partition(ListUtils.emptyIfNull(conditionList), 100);
        for (List<Condition> partition : partitions) {
            conditionDao.batchAdd(partition);
        }
    }

    /**
     * 删除组件过滤器
     *
     * @param tenantId 租户id
     * @param componentIds 组件id
     */
    public void delete(Long tenantId, List<Long> componentIds) {
        if (CollectionUtils.isNotEmpty(componentIds)) {
            conditionDao.delete(tenantId, componentIds);
        }
    }

    /**
     * 查询组件过滤器
     *
     * @param tenantId 租户ID
     * @param componentIds 组件ID
     * @return 组件过滤器
     */
    public List<Condition> list(Long tenantId, List<Long> componentIds) {
        return conditionDao.list(tenantId, componentIds);
    }

}
